<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css"/>
		<link rel="stylesheet" type="text/css" href="../css/aui.css"/>
		<link rel="stylesheet" type="text/css" href="../icon/aosen/css/font-awesome.min.css" />
    <style>
    	body,html{
				  background:#f2f2f2;
    	}
    	.box{
    		display:flex;
			display:-webkit-flex;
			height: 2.5rem;
			width: 100%;
			margin-bottom: 1px;
			background: white;
			padding: 0 0.5rem
    	}
    	.box div{
    		height: 100%;
    		line-height: 2.5rem
    	}
    	.pictures{
    		width:100%;
    		height:auto;
    		background:white;
    	}
    	.pictures .picture{
    		margin:0.3rem;
    		width:4rem;
    		height:4rem;
    		float:left;
    		overflow:hidden;
    		text-align:center;
    		line-height: 4rem;
    		background:#DDDDDD;
    		color:white;
    	}
    	.pictures .picture img{
    		width:100%;
    		height:100%;
    		display:block;
    	}
    	.pictures div:last-child{

    		clear:both;
    	}
    </style>
</head>
<body>
   <div class="box">
   		<div>
   			<span style="color: red;margin-right: 0.3rem;font-size: 3vw">*</span>游戏名称：
   		</div>
   		<div class="aui-list-item-input">
   			<input type="text"  placeholder="请输入游戏名称" style="height: 2.5rem" id="gameName"/>
				<!-- <select id="gameName">
          <option value="0">请选择您要发布的游戏名称</option>
        </select> -->
   		</div>
   </div>
   <div class="box">
   		<div>
   			<span style="color: red;margin-right: 0.3rem;font-size: 3vw">*</span>游戏平台：
   		</div>
   		<div>
   			<input type="text"  placeholder="请输入游戏平台" style="height: 2.5rem" id="platform"/>
   		</div>
   </div>
   <div class="box">
   		<div>
   			<span style="color: red;margin-right: 0.3rem;font-size: 3vw">*</span>游戏区服：
   		</div>
   		<div>
   			<input type="text"  placeholder="请输入游戏区服" style="height: 2.5rem" id="server"/>
   		</div>
   </div>
   <div class="box">
   		<div>
   			<span style="color: red;margin-right: 0.3rem;font-size: 3vw">*</span>游戏底价：
   		</div>
   		<div>
   			<input type="number"  placeholder="请输入游戏底价" style="height: 2.5rem" id="price"/>
   		</div>
   </div>
   <div class="box">
   		<div>
   			<span style="color: red;margin-right: 0.3rem;font-size: 3vw">*</span>游戏简介：
   		</div>
   		<div>
   			<input type="text"  placeholder="请输入游戏简介" style="height: 2.5rem" id="word"/>
   		</div>
   </div>


  <!-- <div class="box">
   		<div style="padding-left: 0.5rem">
   			游戏截图：
   		</div>
   </div>
   <div class="pictures">
   		<div class="picture" onclick="uploadImg()">
   			<i class="aui-iconfont aui-icon-plus" style="font-size: 2rem"></i>
   		</div>
   		<div></div>

   </div>-->
   <div class="box" style="margin-top: 1px;">
   		<div style="padding-left: 0.5rem">
   			其他备注：
   		</div>
   </div>
   <div style="width: 100%;background: white;padding: 0.5rem 0.5rem;margin-bottom:2.5rem">
   		<textarea name="" cols="30" rows="10" placeholder="请输入其他备注信息" id="discribe" style="height:auto;overflow:scroll"></textarea>
   </div>
   <div style="position: fixed;bottom: 0;left: 0;width: 100%;height: 2.5rem;text-align: center;line-height: 2.5rem;background: #e14104;color: white;font-size: 5.5vw;" onclick="submit()">提交</div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/request.js"></script>
<script type="text/javascript">
	var imgArray = [];
	apiready = function(){
		getIntData();
	};
	function getIntData(){
		var data = {};
		requestData('Goods/getGameList',data,'NO','NO','NO',_callbackList);
	}
	function _callbackList(ret){
		if(ret.status == 200){
			if(ret.list.length>0){
				var html='';
				for(var i=0;i<ret.list.length;i++){
					html+='<option value="'+ret.list[i].id+'">'+ret.list[i].game_name+'</option>';
				}
				$api.append($api.byId('gameName'), html);

			}
		}
	}

	function uploadImg(){
		api.actionSheet({
		    cancelTitle: '取消',
		    buttons: ['相机', '照片']
		}, function(ret, err) {
		    var index = ret.buttonIndex;
		    if(index==1){
		    	getPicture('camera')
		    }
		    if(index==2){
		    	getPicture('library');
		    }
		});
	}
	function getPicture(type){
		api.getPicture({
		    sourceType: type,
		    encodingType: 'jpg',
		    mediaValue: 'pic',
		    destinationType: 'url',
		    allowEdit: false,
		    quality: 100,
		    saveToPhotoAlbum: false
		}, function(ret, err) {
		    if (ret) {
		    	if(ret.data != ''){
		    		imgArray.push(ret.data);
		    		var html = '';

		    		if(imgArray.length>0){
		    			for(var i=0;i<imgArray.length;i++){
		    				html+='<div class="picture" onclick="pictureBrowse('+i+')"><img src="'+imgArray[i]+'"/></div><div></div>';
		    			}
		    		}
		    		html+='<div class="picture" onclick="uploadImg()">';
		    		html+='<i class="aui-iconfont aui-icon-plus" style="font-size: 2rem"></i>';
		    		html+='</div>';
		    		html+='<div></div>';

		    		$api.html($api.dom('.pictures'), html);

		    	}
		    } else {
		    	api.alert({
		    		msg:"获取图片失败"
	            });
		    }
		});
	}
	function pictureBrowse(index){
		api.openWin({
	        name: 'pictureBrowse',
	        url: 'pictureBrowse.html',
	        pageParam:{
	        	images:imgArray,
	        	index:index
	        },
	        animation:{
	        	type:'fade',
	        	duration:300
	        }
        });
	}
	function submit(){
		if($api.val($api.byId('gameName')) == ''){
			api.toast({
                msg: '请输入游戏名称',
                duration: 4000,
                location: 'bottom'
            });
            return false;
		}
		if($api.trimAll($api.val($api.byId('platform'))) == ''){
			api.toast({
                msg: '游戏平台必填！',
                duration: 4000,
                location: 'bottom'
            });
            return false;
		}
		if($api.trimAll($api.val($api.byId('server'))) == ''){
			api.toast({
                msg: '游戏区服必填！',
                duration: 4000,
                location: 'bottom'
            });
            return false;
		}
    if($api.val($api.byId('price')) == ''){
			api.toast({
                msg: '游戏价格必填！',
                duration: 4000,
                location: 'bottom'
            });
            return false;
		}
    if($api.trimAll($api.val($api.byId('word'))) == ''){
			api.toast({
                msg: '游戏简介必填！',
                duration: 4000,
                location: 'bottom'
            });
            return false;
		}
//	if(imgArray.length<1){
//		api.toast({
//          msg: '至少上传一张截图！',
//          duration: 4000,
//          location: 'bottom'
//      });
//      return false;
//	}
    var data = {};
    data['values'] = {};
    data['files'] = {};
    data['values']['game_name'] = $api.val($api.byId('gameName'));
    data['values']['goods_price'] = $api.val($api.byId('price'));
    data['values']['server'] = $api.val($api.byId('server'));
    data['values']['goods_discribe'] = $api.val($api.byId('discribe'));
    data['values']['goods_word'] = $api.val($api.byId('word'));
    data['values']['user_id'] = $api.getStorage('userId');
    data['values']['platform'] = $api.val($api.byId('platform'));
    for(var i=0;i<imgArray.length;i++){
    	data['files']['file'+i] = imgArray[i];
    }

    requestData('Goods/givePricePro',data,'NO','NO','NO',_callbackRelt);
	}
  function _callbackRelt(ret){
    api.toast({
        msg: ret.msg,
        duration: 2000,
        location: 'bottom'
    });
    if(ret.status == 200){
      setTimeout(function(){
        api.closeWin();

      },2000)
    }

  }
</script>
</html>
